package com.wopinla.service.impl;
import com.wopinla.dao.*;
import com.wopinla.pojo.order;
import com.wopinla.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service   //添加注解
public class orderServiceImpl implements orderService
{
    @Autowired
    private orderDao orderDao;
    @Override
    public int addorder(Map<String,Object> map)
    {
        int gid=(int) map.get("gid");
        Integer price=orderDao.getGoodsPriceById(gid);
        System.out.println(price);


        Integer uprice=orderDao.getUserPriceById((int)map.get("uid"));
        System.out.println(uprice);

//        Integer activityPrice;
//        Integer aaa=orderDao.getActivityPriceById(gid);
//        if(aaa==null)
//        {
//            activityPrice=0;
//        }
//        else
//        {
//            activityPrice=aaa;
//        }
//        System.out.println(activityPrice);
        Integer rprice=price;
        switch (uprice)
        {
            case 5:
                rprice=rprice-20;
                break;
            case 4:
                rprice=rprice-15;
                break;
            case 3:
                rprice=rprice-10;
                break;
            case 2:
                rprice=rprice-5;
                break;
            default:
                break;
        }

        int dprice=price-rprice;
        dprice=dprice*(int)map.get("num");
        price=price*(int)map.get("num");
        rprice=rprice*(int)map.get("num");
        map.put("price",price);
        map.put("rprice",rprice);
        map.put("dprice",dprice);
        SimpleDateFormat df = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String otime=df.format(new Date());
        map.put("otime",otime);
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            System.out.println("Key = " + entry.getKey() + ",  Value = " + entry.getValue());
        }
        return orderDao.addOrder(map);
    }
    @Override
    public int removeorder(Map<String,Object> map)
    {
        return orderDao.removeOrder(map);
    }
    @Override
    public order checkorder(Map<String,Object> map)
    {
        return orderDao.checkOrder(map);
    }
    @Override
    public List<order> checkuserorder(Map<String,Object> map)
    {
        return orderDao.checkuserOrder(map);
    }
    @Override
    public List<order> checkallorder()
    {
        return orderDao.checkallorder();
    }
    @Override
    public int acceptorder(int oid)
    {
        return orderDao.acceptorder(oid);
    }
    @Override
    public int refuseorder(int oid)
    {
        return orderDao.refuseorder(oid);
    }
}
